package Application.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.UUID;

import javax.annotation.Resource;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import Application.dao.EssayDao;
import Application.entity.Essay;
import Application.entity.Middle;
import Application.entity.Result;
import Application.service.EssayService;
@CrossOrigin	
@RestController
@RequestMapping("/Essay")
public class EssayControl {
	
	@Resource
	private EssayService service;
	
	@PostMapping("/insertEssay")
	public Result insertEssay(Essay essay) {
		return service.insertEssay(essay);
	}
	
	@PostMapping("/deleteEssayById")
	public Result deleteEssayById(int id) {
		return service.deleteEssayById(id);
	}
	
	
	@GetMapping("/findEssayList")
	public  List<Essay>  findEssayList(){
		return service.findEssayList();
	} 
	
	@PostMapping("/findEssayById")
	public Essay findEssayById(int id) {
		return service.findEssayById(id);
	}
	
	@PostMapping("/vague")
	public List<Essay> vague(String value){
		return service.vague(value);
	}
	
	@PostMapping("/findCollectEssay")
	public List<Essay>  findCollectEssay(int collectorid){
		return service.findCollectEssay(collectorid);
	}
	
	@PostMapping("/findEssayByAuthor")
	public List<Essay> findEssayByAuthor(int authorid){
		return service.findEssayByAuthor(authorid);
	}
	
 //	@PostMapping("/insertEssay")
//	public Result insertEssay(Middle middle) {
//		System.out.println("调用了upload");
//		MultipartFile file=middle.getFile();
//		String localPath="D:/Picture/";
//		String Oldname=file.getOriginalFilename();
//		String uuid = UUID.randomUUID().toString().replace("-", "").toLowerCase();
//		String filename=null;	
//		filename=localPath+uuid+Oldname.substring(Oldname.lastIndexOf("."));
//		File targetFile=new File(filename);
//		try {
//			file.transferTo(targetFile);
//			System.out.println(middle.getTitle());
//			System.out.println(middle.getContent());
//			System.out.println("success");
//		} catch (Exception e) {
//			System.out.println("fail");
//		}
//		return service.insertEssay(middle);
//	}
}
